package com.ruoyi.basedata.service.impl;

import com.ruoyi.basedata.domain.ConcentratorCommandLogs;
import com.ruoyi.basedata.mapper.ConcentratorCommandLogsMapper;
import com.ruoyi.basedata.service.IConcentratorCommandLogsService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 集中器命令下发日志Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-25
 */
@Service
public class ConcentratorCommandLogsServiceImpl implements IConcentratorCommandLogsService
{
    @Autowired
    private ConcentratorCommandLogsMapper concentratorCommandLogsMapper;

    /**
     * 查询集中器命令下发日志
     *
     * @param id 集中器命令下发日志主键
     * @return 集中器命令下发日志
     */
    @Override
    public ConcentratorCommandLogs selectConcentratorCommandLogsById(Long id)
    {
        return concentratorCommandLogsMapper.selectConcentratorCommandLogsById(id);
    }

    /**
     * 查询集中器命令下发日志列表
     *
     * @param concentratorCommandLogs 集中器命令下发日志
     * @return 集中器命令下发日志
     */
    @Override
    public List<ConcentratorCommandLogs> selectConcentratorCommandLogsList(ConcentratorCommandLogs concentratorCommandLogs)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (!Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_ADMIN)) {
            Long userId = user.getUserId();
            concentratorCommandLogs.setSysUserId(userId);
        }
        if (Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_NORMAL_USER)) {
            concentratorCommandLogs.setTenantId(user.getTenantId());
        }
        return concentratorCommandLogsMapper.selectConcentratorCommandLogsList(concentratorCommandLogs);
    }

    /**
     * 新增集中器命令下发日志
     *
     * @param concentratorCommandLogs 集中器命令下发日志
     * @return 结果
     */
    @Override
    public int insertConcentratorCommandLogs(ConcentratorCommandLogs concentratorCommandLogs)
    {
        return concentratorCommandLogsMapper.insertConcentratorCommandLogs(concentratorCommandLogs);
    }

    /**
     * 修改集中器命令下发日志
     *
     * @param concentratorCommandLogs 集中器命令下发日志
     * @return 结果
     */
    @Override
    public int updateConcentratorCommandLogs(ConcentratorCommandLogs concentratorCommandLogs)
    {
        return concentratorCommandLogsMapper.updateConcentratorCommandLogs(concentratorCommandLogs);
    }

    /**
     * 批量删除集中器命令下发日志
     *
     * @param ids 需要删除的集中器命令下发日志主键
     * @return 结果
     */
    @Override
    public int deleteConcentratorCommandLogsByIds(Long[] ids)
    {
        return concentratorCommandLogsMapper.deleteConcentratorCommandLogsByIds(ids);
    }

    /**
     * 删除集中器命令下发日志信息
     *
     * @param id 集中器命令下发日志主键
     * @return 结果
     */
    @Override
    public int deleteConcentratorCommandLogsById(Long id)
    {
        return concentratorCommandLogsMapper.deleteConcentratorCommandLogsById(id);
    }
}
